<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>最长快乐前缀</title>
</head>
<body>
  <script>
    function fn(s) {
      const length = s.length;
      if (length === 1) return '';
      for (let i = 1; i < length; i++) {
        const pre = s.slice(0, length - i);
        const suf = s.slice(i, length);
        if (pre === suf) return pre;
      }
      return '';
    }
    console.log(fn('level'))
  </script>
</body>
</html>